package cn.com.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark
 * @ClassName: ServletDemo01
 * @Description:
 * @author: RZS
 * @date: 2021/11/24  16:49
 */
@WebServlet("/s1.do")
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取请求参数
        String uname = request.getParameter("uname");
        String pwd = request.getParameter("pwd");

        // 判断用户名和密码是否相等
        if("zs".equals(uname) && "123456".equals(pwd)){
            // 用户名和密码是否相等
            response.getWriter().write("SUCCESS");
        }else{
            // 登录失败
            request.setAttribute("msg", "用户名或者密码错误");
            // 转发
            request.getRequestDispatcher("/jsp/jsp01.jsp").forward(request, response);
        }
    }
}
